package com.realbrand.net.realbrandpay.ui.activity.wallet;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.realbrand.net.realbrandpay.R;
import com.realbrand.net.realbrandpay.base.BaseActivity;
import com.realbrand.net.realbrandpay.base.FirstActivity;
import com.realbrand.net.realbrandpay.ui.activity.ADSActivity;
import com.realbrand.net.realbrandpay.ui.activity.login.LoginActivity;
import com.realbrand.net.realbrandpay.ui.activity.mall.MallActivity;
import com.realbrand.net.realbrandpay.ui.activity.shopcar.ShopCarActivity;
import com.realbrand.net.realbrandpay.ui.activity.wallet.bill.BillActivity;
import com.realbrand.net.realbrandpay.ui.activity.wallet.order.OrderActivity;
import com.realbrand.net.realbrandpay.ui.activity.wallet.personer.AccountActivity;
import com.realbrand.net.realbrandpay.ui.activity.wallet.set.SettingActivity;
import com.realbrand.net.realbrandpay.ui.activity.wallet.set.WalletLogoutActivity;
import com.realbrand.net.realbrandpay.ui.activity.wallet.withdraw.WithdrawActivity;
import com.realbrand.net.realbrandpay.untils.Static;
import com.realbrand.net.realbrandpay.zxing.app.CaptureActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/3.
 */

public class WalletActivity extends FirstActivity {
    @BindView(R.id.wallet_tv_money)
    TextView walletTvMoney;
    @BindView(R.id.wallet_toolbar_tv_setting)
    TextView walletToolbarTvSetting;
    @BindView(R.id.wallet_toolbar)
    Toolbar walletToolbar;

    double money;
    @BindView(R.id.wallet_iv)
    ImageView walletIv;
    @BindView(R.id.walletActivity_liner_withdraw)
    LinearLayout walletActivityLinerWithdraw;
    @BindView(R.id.walletActivity_liner_scan)
    LinearLayout walletActivityLinerScan;
    @BindView(R.id.walletActivity_liner_bill)
    LinearLayout walletActivityLinerBill;
    @BindView(R.id.walletActivity_liner_personal)
    LinearLayout walletActivityLinerPersonal;
    @BindView(R.id.wallet_tab_scan)
    TextView walletTabScan;
    @BindView(R.id.wallet_tab_mall)
    TextView walletTabMall;
    @BindView(R.id.wallet_tab_shop)
    TextView walletTabShop;

    private String account;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        //判断如果用户登录了，那么显示余额
        if (LoginActivity.isLogin) {
            SharedPreferences sharedPreferences = getSharedPreferences("userMassage", MODE_PRIVATE);
            String balance = sharedPreferences.getString("balance", "0.00");
            account = sharedPreferences.getString("account", "");
            walletTvMoney.setText(balance);
        }
        setOnClick();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.wallet_activity;
    }

    @Override
    protected void setOnClick() {
        walletActivityLinerPersonal.setOnClickListener(this);
        walletActivityLinerBill.setOnClickListener(this);
        walletActivityLinerScan.setOnClickListener(this);
        walletActivityLinerWithdraw.setOnClickListener(this);
        walletToolbarTvSetting.setOnClickListener(this);
        walletTabMall.setOnClickListener(this);
        walletTabScan.setOnClickListener(this);
        walletTabShop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.walletActivity_liner_personal:
                //点击跳转到账户页面
                startActivity(new Intent(this, AccountActivity.class));
                finish();
                break;
            //账单
            case R.id.walletActivity_liner_bill:
                startActivity(new Intent(this, BillActivity.class));
                finish();
                break;
            //订单
            case R.id.walletActivity_liner_scan:
                startActivity(new Intent(this, OrderActivity.class));
                finish();
                break;
            //提现
            case R.id.walletActivity_liner_withdraw:
                startActivity(new Intent(this, WithdrawActivity.class));
                finish();
                break;
            //设置
            case R.id.wallet_toolbar_tv_setting:
                startActivity(new Intent(this, SettingActivity.class));
                finish();
                break;
            //商城
            case R.id.wallet_tab_mall:
                if (LoginActivity.isLogin) {
                    startActivity(new Intent(this, MallActivity.class));
                    finish();
                } else {
                    Intent intent1 = new Intent(this, LoginActivity.class);
                    intent1.putExtra("whereActivity", "WalletLogout");
                    startActivity(intent1);
                    finish();
                }
                break;
            //扫码
            case R.id.wallet_tab_scan:
                ShopCarActivity.mBoolean = true;
                Intent intent = new Intent(this, CaptureActivity.class);
                Bundle bundle_scan = new Bundle();
                bundle_scan.putString(Static.BundleKey, ADSActivity.VALUE_ADS);
                intent.putExtras(bundle_scan);
                startActivity(intent);
                finish();
                break;
            //购物车
            case R.id.wallet_tab_shop:
                startActivity(new Intent(this, ShopCarActivity.class));
                finish();
                break;
        }

    }


    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            moveTaskToBack(true);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
